home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_08_05 / 8n05128b < prev    next >
Text File  |  1990-04-17  |  779b  |  27 lines

  1.  
  2.  
  3. ---------listing 4---------
  4. #include <string.h>
  5. typedef char ape
  6. #define D define
  7. #D EA register
  8. #D EP unsigned
  9. #D A 1
  10. #D AP (A<<A)
  11. #D P (A<<AP)
  12. #D AE ((P<<P)<<A)
  13. #D PE (((A<<P)<<P)<<P)
  14. #D E ((EP)A>>A)
  15. #D APE {EA EP ape ea=AE;while(ea--) e[ea]=E;}
  16. ;ape a[PE+A],ap,*ae,p[P+A],e[AE];
  17. main(){ape pe,*ep=a;srand((EP)time((long)E));
  18. while(((*(ep++)=getchar())!=-A)&&((ep-a)<PE));
  19. *(ae= --ep)=E;for(ap=E;ap<=P;){APE;if(pe=PA())
  20. {putchar(pe);if(ap<P){p[ap]=pe;ap++;}else{
  21. ep=p+A;while(*ep) *(ep-A)= *(ep++); *(ep-A)=pe;}}else break;}}
  22. PA(){EA ape pe,*ep=a,pa,Ap=E;for(ep=a;ep<ae-P;ep++)
  23. if(!strncmp(ep,p,ap)){e[*(ep+ap)]++;Ap++;}if(!Ap)return(Ap);
  24. pa=rand()%Ap+A;pe=~E,Ap=!Ap;while((Ap+=e[++pe])<pa);return(pe);}
  25. -----------end of listing 4----------------
  26.  
  27.